package model.room
{
	import core.Model;
	
	import events.MailEvent;
	
	import flash.events.EventDispatcher;

	public class MailModel extends EventDispatcher
	{
		private var _mailDatas:Array;
		private var _model:Model = Model.getInstance();
		
		public function MailModel()
		{
			init();
		}
		
		private function init():void
		{
			_mailDatas = [];
		}
		
		public function addMail(mailData:MailData):void
		{
			
			for each (var omailData:MailData in _mailDatas)
			{
				if (omailData.inviteId == mailData.inviteId)
				{
					return;
				} 
			}
			
			_mailDatas.push(mailData);
			
			var mailEvent:MailEvent = new MailEvent(MailEvent.MAIL_ARRIVE);
			dispatchEvent(mailEvent);
		}
		
		public function sendMailAnimation(fromId:int,toId:int):void
		{
			var mailEvent:MailEvent = new MailEvent(MailEvent.MAIL_ANIMATION);
			mailEvent.fromId = fromId;
			mailEvent.toId = toId;
			dispatchEvent(mailEvent);
		}
		
		public function get mailDatas():Array
		{
			return _mailDatas.concat();;
		}
		
		public function sendMailResult():void
		{
			_model.netRemote.sendFriendApplyResult(_mailDatas);
			clear();
		}
		
		public function clear():void
		{
			_mailDatas.length = 0;
		}
	}
}